package datastructure;

//Struktur data untuk pecahan

import java.io.Serializable;

public class Fraction implements Serializable  {
  
  private int x,y;
  
  public Fraction (int x, int y) {
    this.x = x;
    this.y = y;
  }
  
  public int getX () {
    return x;
  }
  
  public int getY() {
    return y;
  }
  
  public double getDouble () {
    return (double)x / (double)y;
  }
  
  @Override
  public String toString() {
    return x + "/" + y;
  }
  
  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    } 
    if (o == null || getClass() != o.getClass()) {
      return false;
    }
    
    Fraction frac  = (Fraction)o;
    
    if (frac.x == x && frac.y == y) {
      return true;
    } else {
      return false;
    }
  }

  @Override
  public int hashCode() {
    int hash = 5;
    hash = 37 * hash + x;
    hash = 37 * hash + y;
    return hash;
  }
   
}
